﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Emoney.Spider.Basic
{
    public static class OTO
    {
        /// <summary>
        /// GoInt
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int? ToInt(object obj)
        {
            try
            {
                if (obj == null || obj == "")
                    return null;
                else
                    return Convert.ToInt32(obj);
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// GoToInt
        /// </summary>
        /// <param name="par"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static int ToInt(object par, int v)
        {
            if (par == null || par.ToString() == "")
                return v;
            else
            {
                try
                {
                    return Convert.ToInt32(par);
                }
                catch
                {
                    return v;
                }
            }
        }

        /// <summary>
        /// ToDecimal
        /// </summary>
        /// <param name="par"></param>
        /// <returns></returns>
        public static decimal? ToDecimal(object par)
        {
            try
            {
                if (par == null || par.ToString() == "")
                    return null;
                else
                {
                    return Convert.ToDecimal(par);
                }
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// ToDecimal
        /// </summary>
        /// <param name="par"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static decimal ToDecimal(object par, decimal v)
        {
            if (par == null || par.ToString() == "")
                return Convert.ToDecimal(v);
            else
            {
                try
                {
                    return Convert.ToDecimal(par);
                }
                catch
                {
                    return Convert.ToDecimal(v);
                }
            }
        }

        /// <summary>
        /// ToDate
        /// </summary>
        /// <param name="par"></param>
        /// <returns></returns>
        public static DateTime? ToDate(object par)
        {
            if (par == null || par.ToString() == "")
                return null;
            else
            {
                try
                {
                    return Convert.ToDateTime(par);
                }
                catch
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// ToDate
        /// </summary>
        /// <param name="par"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static DateTime ToDate(object par, DateTime v)
        {
            if (par == null || par.ToString() == "")
                return v;
            else
            {
                try
                {
                    return Convert.ToDateTime(par);
                }
                catch
                {
                    return v;
                }
            }
        }

        /// <summary>
        /// ToStr
        /// </summary>
        /// <param name="par"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static string ToStr(Object par)
        {
            if (par == null)
                return null;
            else
                return par.ToString();
        }

        /// <summary>
        /// ToStr
        /// </summary>
        /// <param name="par"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static string ToStr(Object par, string v)
        {
            if (par == null)
                return v;
            else
                return par.ToString();
        }


        public static string GetZD(int v)
        {
            string rel = "";
            switch (v)
            {
                case -1:
                    rel = "采集URL";
                    break;
                case 0:
                    rel = "末签发";
                    break;
                case 1:
                    rel = "已签发";
                    break;
                default:
                    break;
            }
            return rel;
        }
    }
}
